1 Background

The objective of this study was to examine how non-autistic and autistic process social rewards, and whether participants would be able to learn whether two individuals were more similar or dissimilar to them. Prior to the fMRI scan, participants completed a survey of their interests (e.g. I am an animal lover). Using this survey, with over 200 responses, we matched other real participants to each other, such that every participant had a similar peer which shared 75% of the same interests, and a dissimilar peer which shared only 25% of the same interests. In the fMRI task, participants were shown an individuals name, either Shiloh or Charlie. These were the similar or dissimilar peers. For each trial, participants were first shown the peer’s name, then their own response to a survey question (e.g. animal lover indicating that the participant had responded that they love animals). Next, participants had to press a button to learn about the shown peer. The feedback consisted of a thumbs up with a “Me too!” message or a thumbs down with a “Not me!” message, indicating whether the peer had shared that interest or not. There was also a computer peer condition in which the computer gave 50% positive feedback as a “match” or “no match”.

1.1 Task Design

Social Reward Task
Social Reward Task

This was an event-related design with four runs of the task.

1.2 Setup Up

1.2.1 Import Packages

library(dplyr)
library(tidyr)
library(ggplot2)
library(emmeans)
library(lmerTest)
require(gridExtra)
library(multcomp)
library(plyr)

1.2.2 Define directories

data_dir <- 'derivatives/task_socialreward/data/'

1.2.3 Find participants

subj_df <- read.csv('participants.tsv', sep = '\t')

# Remove prefix from subject IDs
subj_df$participant_id<-gsub("sub-SCN","SCN_",as.character(subj_df$participant_id))

print(paste('Found ', length(subj_df$participant_id), ' participants'))
## [1] "Found  85  participants"

2 Data Cleaning

# Create an empty dataframe to fill with all the participant data
rt_data <- data.frame(matrix(ncol = 6, nrow = 0))

# Name columns for the empty dataframe  
colnames(rt_data) <- c('ParticipantID', 'Run', 'X', 'rating', 'ConditionName', 
                       'Correct_RT')


# Import Data

for (subj in subj_df$participant_id) {
  
  # Find data for all runs
  run_files <- Sys.glob(paste(data_dir, subj, '/*-errors.csv', sep = ''))
  
  # Loop through runs and combine into one df
  for (run_file in run_files){
    temp_run_data <- read.csv(run_file)
    
    if (sum(temp_run_data$redcap_v_task) == 0) {
      
      # Filter for relevant columns
      temp_run_data_fltr <- temp_run_data[,colnames(rt_data)]
      
      # Append to entire df
      rt_data <- rbind(rt_data, temp_run_data_fltr)
    } 
  }
}

# Rename trial number column 
names(rt_data)[names(rt_data) == 'X'] <- 'trial_num'

Add group (e.g. autistic, non-autistic) info to reaction time dataframe

rt_data <- merge(rt_data, subj_df, 
                 by.x = 'ParticipantID', by.y = 'participant_id')

# Rename column
rt_data <- rt_data %>% rename_at('ParticipantID', ~'participant_id')

Create column for the peer conditions info and valence of feedback

rt_data <- rt_data %>% separate(ConditionName, c('Valence', 'Condition'))

rt_data$Valence <- gsub('LowReward','negative',as.character(rt_data$Valence))
rt_data$Valence <- gsub('HighReward','positive',as.character(rt_data$Valence))

Calculate the valence of the previous trial within each condition

# Create an empty column of NAs
rt_data$Valence_prev <- NA

for (subj in unique(rt_data$participant_id)) {
  # Create a list of the runs for this participant
  temp_run_list <- unique(rt_data[rt_data$participant_id == 'SCN_101', 'Run'])
  
  for (run in temp_run_list) {
    
    for (cond in c('SimPeer', 'DisPeer', 'Computer')) {
      
      # Calculate the number of trials for a given condition per run per subject
      temp_len <- length(rt_data[rt_data$participant_id == subj & 
                                 rt_data$Run == run & 
                                 rt_data$Condition == cond, 'Valence'])
      
      # Create a list of the trial valences, excluding the first trial of that run
      # since nothing was shown before that trial in the run
      temp_val <- rt_data[rt_data$participant_id == subj & 
                          rt_data$Run == run & 
                          rt_data$Condition == cond, 'Valence'][1:temp_len-1]
      
      # Fill in the previous trial valence for that condition
      rt_data[rt_data$participant_id == subj & 
              rt_data$Run == run & 
              rt_data$Condition == cond, 'Valence_prev'] <- c(NA, temp_val)
    }
  }

}

Make group data an nominal data type

rt_data$group <- gsub('1','non-autistic',as.character(rt_data$group))
rt_data$group <- gsub('2','autistic',as.character(rt_data$group))
head(rt_data)

2.1 Missed trials

When a participant did not press the correct button, the feedback was “no data”. This occurred in two instances:

  • When the participant made no button press
  • When the participant hit the incorrect button, and did not hit the correct button before the trial timed out

In both these instances, the participant was not paying attention and so we should exclude these trials. If this was the case for more than 20% of the run, then we should exclude data from the entire run.

# Find participant runs with more than 20% missed trials

exclude_subj_runs <- data.frame(participant_id = character(), Run = character(), stringsAsFactors = FALSE)

# Create a list of all subject IDs
subj_list <- unique(rt_data$participant_id)

for (subj in subj_list) {
  
  # Filter for subject specific data
  temp_subj_data <- rt_data[rt_data$participant_id == subj, ]
  
  # Find runs per subject
  temp_runs <- unique(temp_subj_data$Run)
  
  for (run in temp_runs) {
    
    # Filter for run specific data
    temp_run_rt <- temp_subj_data[temp_subj_data$Run == run, 'Correct_RT']
    
    # Calculate the percentage of missed trials
    temp_na_perc <- sum(is.na(temp_run_rt)) / length(temp_run_rt)
    
    # If more than 20% missed trials, exclude the participant run
    if (temp_na_perc > 0.20) {
      exclude_subj_runs[nrow(exclude_subj_runs) + 1,] <- c(subj, run)
    }
  }
}

print(paste('Excluding',nrow(exclude_subj_runs),'runs from',
            length(unique(exclude_subj_runs$participant_id)),
            'participants'))
## [1] "Excluding 2 runs from 2 participants"

Use the list of bad participant runs to remove that data from the larger dataframe

for (i in 1:nrow(exclude_subj_runs)) {
  temp_drop_idx <- which(rt_data$participant_id == exclude_subj_runs[i, "participant_id"] & 
                         rt_data$Run == exclude_subj_runs[i, "Run"])
  
  rt_data <- rt_data[-temp_drop_idx, ]
}

With the remaining data, create column for missing trials. This might be interesting as it could be an indicator of learning. For example, if participants have learned who the dissimilar peer is, perhaps they would respond less for those trials than the similar peer trials. Accurate button presses will be coded as 1, and inaccurate will be coded as 0.

rt_data$accuracy <- 1
rt_data[is.na(rt_data$Correct_RT),'accuracy'] <- 0

table(rt_data$accuracy)
## 
##    0    1 
##   87 6007

Add run as a categorical variable (don’t end up using)

rt_data$Run.f <- factor(rt_data$Run)

2.2 Transforming Data

Using method from Jones et al., 2014: “Reaction times to the cue after the wink occurred were z-score transformed to each individual’s mean and standard deviation after first removing outliers (defined as reaction times 3 standard deviations above or below the individual’s mean reaction time) and log transforming each reaction time to satisfy normality assumptions.”

# Create copy of the data
rt_data_mod <- data.frame(rt_data)

# Remove outliers greater than 3SD
#rt_data_mod[( rt_data_mod$ParticipantID %in% "SCN_101" & rt_data_mod$Correct_RT > 3*temp_sd),]

# Log transform
rt_data_mod$Correct_RT_log <- log(rt_data$Correct_RT)

# Create empty column for log zscored data
rt_data_mod$Correct_RT_logz <- NA

for (subj in subj_df$participant_id) {
# Calculate mean and SD
  temp_subj_data <- filter(rt_data_mod, participant_id == subj)
  temp_mean <- mean(temp_subj_data$Correct_RT_log, na.rm = TRUE)
  temp_sd <- sd(temp_subj_data$Correct_RT_log, na.rm = TRUE)
  rt_data_mod[(rt_data_mod$participant_id %in% subj),'Correct_RT_logz'] <- (rt_data_mod[(rt_data_mod$participant_id %in% subj),'Correct_RT_log'] - temp_mean)/temp_sd
}
plot1 <- ggplot(rt_data_mod, aes(x=Correct_RT)) + geom_histogram() + theme_classic()

plot2 <- ggplot(rt_data_mod, aes(x=Correct_RT_logz)) + geom_histogram() + theme_classic()

grid.arrange(plot1, plot2, ncol=2)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

The raw reaction times are not normally distributed and right-skewed. This may be a result of the task design where participants were given a window to view the interest and the peer condition, then a separate window to respond. So all participants were forced to view the condition for the same amount of time. After our log and z-transform, we have a normal distribution for the reaction times.

Lastly, we will set the similar peer condition as the reference group for the regression analyses

rt_data_mod$Condition <- relevel(factor(rt_data_mod$Condition), ref = "SimPeer")

3 Non-Autistic Adolescents

rt_data_mod_typ <- filter(rt_data_mod, group == 'non-autistic')
print(paste("There are ",length(unique(rt_data_mod_typ$participant_id)), 
            " autistic participants"))
## [1] "There are  54  autistic participants"

3.1 Run and Reaction Time

Use a linear mixed-effects model to model both the fixed effects of our conditions of interest, and the random effects of the participants. An example of a random effect would be that some participants are just faster to respond in all conditions.

model_run_typ <- lmer(Correct_RT_logz ~ Run + (1 + Run | participant_id), 
                data = rt_data_mod_typ)
## boundary (singular) fit: see help('isSingular')
summary(model_run_typ)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Correct_RT_logz ~ Run + (1 + Run | participant_id)
##    Data: rt_data_mod_typ
## 
## REML criterion at convergence: 11115.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.0985 -0.6809 -0.1179  0.5919  5.4617 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev. Corr 
##  participant_id (Intercept) 0.19447  0.4410        
##                 Run         0.03165  0.1779   -1.00
##  Residual                   0.92642  0.9625        
## Number of obs: 3995, groups:  participant_id, 54
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)  0.27184    0.07235 55.77685   3.757 0.000413 ***
## Run         -0.11028    0.02861 55.26867  -3.854 0.000305 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##     (Intr)
## Run -0.976
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')

This analysis shows that participants are getting faster at responding throughout the task (B = -0.09, p = .0002).

ggplot(data = rt_data_mod_typ, aes(x=Run, y=Correct_RT_logz, group=Run)) + 
  geom_boxplot(outlier.shape = NA) + 
  geom_jitter(color='black', alpha=0.05) + 
  theme_classic()
## Warning: Removed 60 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 60 rows containing missing values (`geom_point()`).

The box plots show this significant tread, and the individual response times for all participants.

3.2 Peer Category and Run Predicting Reaction Time

Next, we will examine whether there are differences in reaction time to our peer conditions throughout the task. Again, the conditions were were getting feedback from a similar peer (75% positive feedback), dissimilar peer (25% positive feedback), or a random computer (50% positive feedback).

model_run_peer_typ <- lmer(Correct_RT_logz ~ Run*Condition + (1 + Run*Condition | participant_id),
                       data = rt_data_mod_typ)
## boundary (singular) fit: see help('isSingular')
summary(model_run_peer_typ)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: 
## Correct_RT_logz ~ Run * Condition + (1 + Run * Condition | participant_id)
##    Data: rt_data_mod_typ
## 
## REML criterion at convergence: 11117.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.0705 -0.6708 -0.1067  0.5957  5.5091 
## 
## Random effects:
##  Groups         Name                  Variance Std.Dev. Corr                   
##  participant_id (Intercept)           0.169297 0.41146                         
##                 Run                   0.025260 0.15893  -0.99                  
##                 ConditionComputer     0.033757 0.18373   0.21 -0.34            
##                 ConditionDisPeer      0.044915 0.21193   0.03 -0.18  0.47      
##                 Run:ConditionComputer 0.004528 0.06729  -0.37  0.38 -0.72  0.26
##                 Run:ConditionDisPeer  0.005272 0.07261  -0.30  0.39 -0.14 -0.88
##  Residual                             0.917311 0.95776                         
##       
##       
##       
##       
##       
##       
##  -0.46
##       
## Number of obs: 3995, groups:  participant_id, 54
## 
## Fixed effects:
##                         Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)             0.308262   0.086104  62.015310   3.580 0.000674 ***
## Run                    -0.130873   0.032519  65.163079  -4.025 0.000151 ***
## ConditionComputer      -0.112151   0.093730  74.876461  -1.197 0.235263    
## ConditionDisPeer        0.005141   0.094888 106.060195   0.054 0.956896    
## Run:ConditionComputer   0.070135   0.034817  94.821722   2.014 0.046803 *  
## Run:ConditionDisPeer   -0.009153   0.034955 126.555238  -0.262 0.793866    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Run    CndtnC CndtDP Rn:CnC
## Run         -0.945                            
## CondtnCmptr -0.462  0.384                     
## ConditnDsPr -0.489  0.403  0.497              
## Rn:CndtnCmp  0.388 -0.419 -0.895 -0.390       
## Rn:CndtnDsP  0.394 -0.407 -0.426 -0.907  0.415
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')

Accounting for the peer condition, task run had a significant impact on reaction times (B = -0.11, p < .001), such that participants were getting faster as the task went on. There was no significant main effect of peer condition. There is a trend for an interaction in which participants had faster reaction times throughout the task for the similar peer condition, in comparison to the computer control condition (B = .05, p = 0.05).

ggplot(data = rt_data_mod_typ, aes(x=factor(Run), y=Correct_RT_logz, fill=Condition)) + 
  geom_boxplot(outlier.shape = NA) + 
  geom_point(alpha=0.05, aes(fill=Condition),
             position = position_jitterdodge(dodge.width = 0.8)) +
  theme_classic()
## Warning: Removed 60 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 60 rows containing missing values (`geom_point()`).

3.3 Previous Feedback and Run Predicting Reaction Time

Another way we can look at reaction time is to examine if reaction times would be effected by the valence of the previous trial from the same condition. For example, when considering to learn about “Shiloh” in the current trial, if Shiloh had given negative feedback in their last trial, perhaps the participants would be less motivated to learn about Shiloh in the current trial.

model_run_prev_val_typ <- lmer(Correct_RT_logz ~ Run*Valence_prev + (1 + Run*Valence_prev | participant_id),
                       data = rt_data_mod_typ)
## boundary (singular) fit: see help('isSingular')
summary(model_run_prev_val_typ)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Correct_RT_logz ~ Run * Valence_prev + (1 + Run * Valence_prev |  
##     participant_id)
##    Data: rt_data_mod_typ
## 
## REML criterion at convergence: 9705.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1390 -0.6798 -0.1149  0.5712  5.3841 
## 
## Random effects:
##  Groups         Name                     Variance Std.Dev. Corr             
##  participant_id (Intercept)              0.256115 0.50608                   
##                 Run                      0.040989 0.20246  -0.99            
##                 Valence_prevpositive     0.009160 0.09571  -0.65  0.74      
##                 Run:Valence_prevpositive 0.007308 0.08549   0.21 -0.33 -0.88
##  Residual                                0.908335 0.95307                   
## Number of obs: 3499, groups:  participant_id, 54
## 
## Fixed effects:
##                           Estimate Std. Error        df t value Pr(>|t|)  
## (Intercept)                0.19459    0.09064  58.39080   2.147   0.0360 *
## Run                       -0.08699    0.03535  57.48221  -2.461   0.0169 *
## Valence_prevpositive      -0.02259    0.07947 418.02877  -0.284   0.7763  
## Run:Valence_prevpositive   0.01823    0.03180  82.82666   0.573   0.5681  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Run    Vlnc_p
## Run         -0.960              
## Vlnc_prvpst -0.521  0.479       
## Rn:Vlnc_prv  0.434 -0.494 -0.885
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
ggplot(data = subset(rt_data_mod_typ, !is.na(Valence_prev)), aes(x=factor(Run), y=Correct_RT_logz, fill=Valence_prev)) + 
  geom_boxplot(outlier.shape = NA) + 
  geom_point(alpha=0.05, aes(fill=Valence_prev),
             position = position_jitterdodge(dodge.width = 0.8)) +
  theme_classic()
## Warning: Removed 55 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 55 rows containing missing values (`geom_point()`).

The valence of the previous within condition trial did not have an impact on reaction times.

3.4 Previous Feedback, Peer Condition, and Run Predicting Reaction Time

Since the previous analysis failed, maybe explicitly adding an interaction for the peer condition will have an impact on reaction times. For example, the valence of the trial might be more salient when it is a similar peer who previously gave you positive feedback or a dissimilar peer who previously gave you negative feedback.

model_run_prev_val_cond_typ <- lmer(Correct_RT_logz ~ Run*Condition*Valence_prev + (1 + Run*Condition*Valence_prev | participant_id),
                       data = rt_data_mod_typ)
## boundary (singular) fit: see help('isSingular')
summary(model_run_prev_val_cond_typ)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Correct_RT_logz ~ Run * Condition * Valence_prev + (1 + Run *  
##     Condition * Valence_prev | participant_id)
##    Data: rt_data_mod_typ
## 
## REML criterion at convergence: 9705
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.0971 -0.6664 -0.1122  0.5801  5.2697 
## 
## Random effects:
##  Groups         Name                                       Variance Std.Dev.
##  participant_id (Intercept)                                0.49936  0.7067  
##                 Run                                        0.06167  0.2483  
##                 ConditionComputer                          0.41102  0.6411  
##                 ConditionDisPeer                           0.33755  0.5810  
##                 Valence_prevpositive                       0.34618  0.5884  
##                 Run:ConditionComputer                      0.04011  0.2003  
##                 Run:ConditionDisPeer                       0.02326  0.1525  
##                 Run:Valence_prevpositive                   0.05275  0.2297  
##                 ConditionComputer:Valence_prevpositive     0.38895  0.6237  
##                 ConditionDisPeer:Valence_prevpositive      0.30569  0.5529  
##                 Run:ConditionComputer:Valence_prevpositive 0.04858  0.2204  
##                 Run:ConditionDisPeer:Valence_prevpositive  0.03431  0.1852  
##  Residual                                                  0.88661  0.9416  
##  Corr                                                             
##                                                                   
##  -0.95                                                            
##  -0.61  0.43                                                      
##  -0.69  0.55  0.85                                                
##  -0.76  0.63  0.92  0.90                                          
##   0.54 -0.44 -0.92 -0.67 -0.87                                    
##   0.61 -0.56 -0.71 -0.95 -0.82  0.60                              
##   0.67 -0.67 -0.72 -0.83 -0.89  0.77  0.89                        
##   0.63 -0.46 -0.98 -0.78 -0.93  0.95  0.64  0.73                  
##   0.56 -0.38 -0.84 -0.88 -0.93  0.74  0.78  0.78  0.86            
##  -0.62  0.55  0.89  0.77  0.94 -0.96 -0.74 -0.91 -0.92 -0.82      
##  -0.65  0.58  0.71  0.76  0.92 -0.73 -0.73 -0.89 -0.78 -0.91  0.87
##                                                                   
## Number of obs: 3499, groups:  participant_id, 54
## 
## Fixed effects:
##                                              Estimate Std. Error         df
## (Intercept)                                  0.147809   0.160307  61.075484
## Run                                         -0.082423   0.058190  66.296283
## ConditionComputer                            0.037726   0.183533  58.174939
## ConditionDisPeer                             0.066323   0.169613  74.268383
## Valence_prevpositive                         0.024458   0.170451  70.427446
## Run:ConditionComputer                        0.025394   0.065503  67.863822
## Run:ConditionDisPeer                        -0.022804   0.058937 123.418055
## Run:Valence_prevpositive                     0.007455   0.064251  64.221114
## ConditionComputer:Valence_prevpositive      -0.072245   0.218281  82.488800
## ConditionDisPeer:Valence_prevpositive        0.001504   0.223466 110.736287
## Run:ConditionComputer:Valence_prevpositive   0.005367   0.080405  90.444899
## Run:ConditionDisPeer:Valence_prevpositive   -0.008702   0.081975  96.674131
##                                            t value Pr(>|t|)
## (Intercept)                                  0.922    0.360
## Run                                         -1.416    0.161
## ConditionComputer                            0.206    0.838
## ConditionDisPeer                             0.391    0.697
## Valence_prevpositive                         0.143    0.886
## Run:ConditionComputer                        0.388    0.699
## Run:ConditionDisPeer                        -0.387    0.699
## Run:Valence_prevpositive                     0.116    0.908
## ConditionComputer:Valence_prevpositive      -0.331    0.742
## ConditionDisPeer:Valence_prevpositive        0.007    0.995
## Run:ConditionComputer:Valence_prevpositive   0.067    0.947
## Run:ConditionDisPeer:Valence_prevpositive   -0.106    0.916
## 
## Correlation of Fixed Effects:
##             (Intr) Run    CndtnC CndtDP Vlnc_p Rn:CnC Rn:CDP Rn:Vl_ CnC:V_
## Run         -0.925                                                        
## CondtnCmptr -0.726  0.628                                                 
## ConditnDsPr -0.788  0.698  0.710                                          
## Vlnc_prvpst -0.808  0.723  0.727  0.758                                   
## Rn:CndtnCmp  0.651 -0.681 -0.910 -0.618 -0.661                            
## Rn:CndtnDsP  0.701 -0.750 -0.620 -0.910 -0.675  0.652                     
## Rn:Vlnc_prv  0.728 -0.788 -0.632 -0.688 -0.904  0.684  0.735              
## CndtnCmp:V_  0.610 -0.532 -0.829 -0.578 -0.778  0.763  0.506  0.682       
## CndtnDsP:V_  0.560 -0.488 -0.531 -0.728 -0.737  0.475  0.660  0.654  0.571
## Rn:CndtC:V_ -0.562  0.592  0.749  0.532  0.722 -0.821 -0.559 -0.769 -0.911
## Rn:CndDP:V_ -0.531  0.562  0.466  0.649  0.674 -0.505 -0.706 -0.717 -0.515
##             CDP:V_ R:CC:V
## Run                      
## CondtnCmptr              
## ConditnDsPr              
## Vlnc_prvpst              
## Rn:CndtnCmp              
## Rn:CndtnDsP              
## Rn:Vlnc_prv              
## CndtnCmp:V_              
## CndtnDsP:V_              
## Rn:CndtC:V_ -0.524       
## Rn:CndDP:V_ -0.910  0.566
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
ggplot(data = subset(rt_data_mod_typ, !is.na(Valence_prev)), aes(x=factor(Run), y=Correct_RT_logz, fill=Condition, alpha=Valence_prev)) + 
  geom_boxplot(outlier.shape = NA) + 
  theme_classic()
## Warning: Using alpha for a discrete variable is not advised.
## Warning: Removed 55 rows containing non-finite values (`stat_boxplot()`).

Makes no difference.

3.5 Are participants learning?

3.5.1 Reaction time difference between similar and dissimilar peers

In the later runs, is there a difference in reaction time between the similar and dissimilar peer conditions? How many participants show this learning effect?

rt_means_subj_cond_run_typ <- ddply(rt_data_mod_typ, c('participant_id','Condition','Run'), 
                                summarise, 
                                mean=mean(Correct_RT, na.rm=TRUE))

Calculate the difference in RT for similar and dissimilar peer conditions at run 4

r4_peer_diff_typ <- data.frame(matrix(ncol = 2, nrow = 0))

# Name columns for the empty dataframe  
colnames(r4_peer_diff_typ) <- c('ParticipantID', 'sim_dis_RT')

for (subj in unique(rt_means_subj_cond_run_typ$participant_id)) {
  temp_subj_data <- rt_means_subj_cond_run_typ[rt_means_subj_cond_run_typ$participant_id == subj, ]
  
  temp_last_run <- temp_subj_data$Run[length(unique(temp_subj_data$Run))]
  
  temp_run_data <- temp_subj_data[temp_subj_data$Run == temp_last_run, ]
  temp_diff <- temp_run_data[temp_run_data$Condition == 'SimPeer', 'mean'] - temp_run_data[temp_run_data$Condition == 'DisPeer', 'mean']
  
  r4_peer_diff_typ[nrow(r4_peer_diff_typ) + 1,] = c(subj,temp_diff)
}

r4_peer_diff_typ$sim_dis_RT <- as.numeric(r4_peer_diff_typ$sim_dis_RT) 

ggplot(r4_peer_diff_typ, aes(x=sim_dis_RT)) + geom_histogram() + theme_classic()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

prop_learn <- nrow(r4_peer_diff_typ[r4_peer_diff_typ$sim_dis_RT < 0, ]) / nrow(r4_peer_diff_typ)

print(paste(round(prop_learn, 4)*100, '% of participants had faster RTs for similar peers than dissimilar peers for their last run.'))
## [1] "44.44 % of participants had faster RTs for similar peers than dissimilar peers for their last run."
t.test(r4_peer_diff_typ$sim_dis_RT, alternative = "two.sided", var.equal = FALSE)
## 
##  One Sample t-test
## 
## data:  r4_peer_diff_typ$sim_dis_RT
## t = -0.23571, df = 53, p-value = 0.8146
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.03332917  0.02631948
## sample estimates:
##    mean of x 
## -0.003504848

3.5.2 Do participants show a decrease in RT after receiving positive feedback compared to negative feedback?

Note that previous valence here is the previous valence of the trial within the same condition.

rt_means_subj_pval_run_typ <- ddply(rt_data_mod_typ, c('participant_id','Valence_prev','Run'), 
                                summarise, 
                                mean=mean(Correct_RT, na.rm=TRUE))

# Remove rows with NA
rt_means_subj_pval_run_typ <- rt_means_subj_pval_run_typ[complete.cases(rt_means_subj_pval_run_typ), ]

Calculate the difference in RT for similar and dissimilar peer conditions at run 4

# Create a new column for for previous valence
r4_peer_diff_typ$pos_neg_RT <- NA

for (subj in unique(rt_means_subj_pval_run_typ$participant_id)) {
  temp_subj_data <- rt_means_subj_pval_run_typ[rt_means_subj_pval_run_typ$participant_id == subj, ]
  
  temp_last_run <- temp_subj_data$Run[length(unique(temp_subj_data$Run))]
  
  temp_run_data <- temp_subj_data[temp_subj_data$Run == temp_last_run, ]
  temp_diff <- temp_run_data[temp_run_data$Valence_prev == 'positive', 'mean'] - temp_run_data[temp_run_data$Valence_prev == 'negative', 'mean']
  
  r4_peer_diff_typ[r4_peer_diff_typ$ParticipantID == subj, 'pos_neg_RT'] = temp_diff
}

r4_peer_diff_typ$pos_neg_RT <- as.numeric(r4_peer_diff_typ$pos_neg_RT) 

ggplot(r4_peer_diff_typ, aes(x=pos_neg_RT)) + geom_histogram() + theme_classic()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

prop_learn <- nrow(r4_peer_diff_typ[r4_peer_diff_typ$pos_neg_RT < 0, ]) / nrow(r4_peer_diff_typ)

print(paste(round(prop_learn, 4)*100, '% of participants had faster RTs for trials that were precided by a positive outcome than negative outcomes, for their last run.'))
## [1] "42.59 % of participants had faster RTs for trials that were precided by a positive outcome than negative outcomes, for their last run."
t.test(r4_peer_diff_typ$sim_dis_RT, alternative = "two.sided", var.equal = FALSE)
## 
##  One Sample t-test
## 
## data:  r4_peer_diff_typ$sim_dis_RT
## t = -0.23571, df = 53, p-value = 0.8146
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.03332917  0.02631948
## sample estimates:
##    mean of x 
## -0.003504848

4 All Participants

4.1 Run and Reaction Time

Use a linear mixed-effects model to model both the fixed effects of our conditions of interest, and the random effects of the participants. An example of a random effect would be that some participants are just faster to respond in all conditions.

model_run <- lmer(Correct_RT_logz ~ Run + (1 + Run | participant_id), 
                data = rt_data_mod)
## boundary (singular) fit: see help('isSingular')
summary(model_run)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Correct_RT_logz ~ Run + (1 + Run | participant_id)
##    Data: rt_data_mod
## 
## REML criterion at convergence: 16765.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.0842 -0.6970 -0.1243  0.5883  5.4264 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev. Corr 
##  participant_id (Intercept) 0.18137  0.4259        
##                 Run         0.02966  0.1722   -1.00
##  Residual                   0.93585  0.9674        
## Number of obs: 6007, groups:  participant_id, 78
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)  0.21907    0.05790 80.84013   3.784 0.000295 ***
## Run         -0.08929    0.02292 79.91655  -3.896 0.000202 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##     (Intr)
## Run -0.975
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')

This analysis shows that participants are getting faster at responding throughout the task (B = -0.09, p = .0002).

ggplot(data = rt_data_mod, aes(x=Run, y=Correct_RT_logz, group=Run)) + 
  geom_boxplot(outlier.shape = NA) + 
  geom_jitter(color='black', alpha=0.05) + 
  theme_classic()
## Warning: Removed 87 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 87 rows containing missing values (`geom_point()`).

The box plots show this significant tread, and the individual response times for all participants.

4.2 Peer Category and Run Predicting Reaction Time

Next, we will examine whether there are differences in reaction time to our peer conditions throughout the task. Again, the conditions were were getting feedback from a similar peer (75% positive feedback), dissimilar peer (25% positive feedback), or a random computer (50% positive feedback).

model_run_peer <- lmer(Correct_RT_logz ~ Run*Condition + (1 + Run*Condition | participant_id),
                       data = rt_data_mod)
## boundary (singular) fit: see help('isSingular')
summary(model_run_peer)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: 
## Correct_RT_logz ~ Run * Condition + (1 + Run * Condition | participant_id)
##    Data: rt_data_mod
## 
## REML criterion at convergence: 16768.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.0564 -0.6915 -0.1185  0.5922  5.4166 
## 
## Random effects:
##  Groups         Name                  Variance Std.Dev. Corr                   
##  participant_id (Intercept)           0.189833 0.4357                          
##                 Run                   0.028503 0.1688   -0.99                  
##                 ConditionComputer     0.034864 0.1867   -0.24  0.18            
##                 ConditionDisPeer      0.027544 0.1660   -0.16  0.03  0.85      
##                 Run:ConditionComputer 0.008687 0.0932    0.19 -0.24 -0.80 -0.37
##                 Run:ConditionDisPeer  0.001369 0.0370   -0.47  0.56 -0.68 -0.78
##  Residual                             0.927594 0.9631                          
##       
##       
##       
##       
##       
##       
##   0.36
##       
## Number of obs: 6007, groups:  participant_id, 78
## 
## Fixed effects:
##                        Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)             0.26104    0.07231  87.39504   3.610  0.00051 ***
## Run                    -0.11089    0.02740  89.13220  -4.047  0.00011 ***
## ConditionComputer      -0.08764    0.07638 125.77454  -1.147  0.25340    
## ConditionDisPeer       -0.03755    0.07566 161.53584  -0.496  0.62037    
## Run:ConditionComputer   0.05288    0.02936  99.44211   1.801  0.07472 .  
## Run:ConditionDisPeer    0.01176    0.02741 596.60039   0.429  0.66815    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Run    CndtnC CndtDP Rn:CnC
## Run         -0.947                            
## CondtnCmptr -0.532  0.468                     
## ConditnDsPr -0.515  0.437  0.525              
## Rn:CndtnCmp  0.474 -0.521 -0.893 -0.440       
## Rn:CndtnDsP  0.400 -0.421 -0.460 -0.899  0.475
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')

Accounting for the peer condition, task run had a significant impact on reaction times (B = -0.11, p < .001), such that participants were getting faster as the task went on. There was no significant main effect of peer condition. There is a trend for an interaction in which participants had faster reaction times throughout the task for the similar peer condition, in comparison to the computer control condition (B = .05, p = 0.05).

ggplot(data = rt_data_mod, aes(x=factor(Run), y=Correct_RT_logz, fill=Condition)) + 
  geom_boxplot(outlier.shape = NA) + 
  geom_point(alpha=0.05, aes(fill=Condition),
             position = position_jitterdodge(dodge.width = 0.8)) +
  theme_classic()
## Warning: Removed 87 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 87 rows containing missing values (`geom_point()`).

4.3 Previous Feedback and Run Predicting Reaction Time

Another way we can look at reaction time is to examine if reaction times would be effected by the valence of the previous trial from the same condition. For example, when considering to learn about “Shiloh” in the current trial, if Shiloh had given negative feedback in their last trial, perhaps the participants would be less motivated to learn about Shiloh in the current trial.

model_run_prev_val <- lmer(Correct_RT_logz ~ Run*Valence_prev + (1 + Run*Valence_prev | participant_id),
                       data = rt_data_mod)
## boundary (singular) fit: see help('isSingular')
summary(model_run_prev_val)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Correct_RT_logz ~ Run * Valence_prev + (1 + Run * Valence_prev |  
##     participant_id)
##    Data: rt_data_mod
## 
## REML criterion at convergence: 14647.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1226 -0.6944 -0.1213  0.5767  5.3651 
## 
## Random effects:
##  Groups         Name                     Variance  Std.Dev. Corr             
##  participant_id (Intercept)              0.1923916 0.43862                   
##                 Run                      0.0322717 0.17964  -0.99            
##                 Valence_prevpositive     0.0004403 0.02098  -0.02  0.19      
##                 Run:Valence_prevpositive 0.0046244 0.06800  -0.06 -0.10 -1.00
##  Residual                                0.9208090 0.95959                   
## Number of obs: 5260, groups:  participant_id, 78
## 
## Fixed effects:
##                            Estimate Std. Error         df t value Pr(>|t|)  
## (Intercept)               1.052e-01  6.835e-02  8.585e+01   1.540   0.1273  
## Run                      -5.500e-02  2.691e-02  8.371e+01  -2.044   0.0441 *
## Valence_prevpositive      5.382e-02  6.379e-02  3.430e+03   0.844   0.3989  
## Run:Valence_prevpositive -5.303e-03  2.511e-02  1.507e+02  -0.211   0.8330  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) Run    Vlnc_p
## Run         -0.951              
## Vlnc_prvpst -0.477  0.415       
## Rn:Vlnc_prv  0.396 -0.453 -0.873
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
ggplot(data = subset(rt_data_mod, !is.na(Valence_prev)), aes(x=factor(Run), y=Correct_RT_logz, fill=Valence_prev)) + 
  geom_boxplot(outlier.shape = NA) + 
  geom_point(alpha=0.05, aes(fill=Valence_prev),
             position = position_jitterdodge(dodge.width = 0.8)) +
  theme_classic()
## Warning: Removed 81 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 81 rows containing missing values (`geom_point()`).

The valence of the previous within condition trial did not have an impact on reaction times.

4.4 Previous Feedback, Peer Condition, and Run Predicting Reaction Time

Since the previous analysis failed, maybe explicitly adding an interaction for the peer condition will have an impact on reaction times. For example, the valence of the trial might be more salient when it is a similar peer who previously gave you positive feedback or a dissimilar peer who previously gave you negative feedback.

model_run_prev_val_cond <- lmer(Correct_RT_logz ~ Run*Condition*Valence_prev + (1 + Run*Condition*Valence_prev | participant_id),
                       data = rt_data_mod)
## boundary (singular) fit: see help('isSingular')
summary(model_run_prev_val_cond)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Correct_RT_logz ~ Run * Condition * Valence_prev + (1 + Run *  
##     Condition * Valence_prev | participant_id)
##    Data: rt_data_mod
## 
## REML criterion at convergence: 14649.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.0892 -0.6899 -0.1207  0.5759  5.2369 
## 
## Random effects:
##  Groups         Name                                       Variance Std.Dev.
##  participant_id (Intercept)                                0.35780  0.5982  
##                 Run                                        0.04917  0.2217  
##                 ConditionComputer                          0.21052  0.4588  
##                 ConditionDisPeer                           0.21733  0.4662  
##                 Valence_prevpositive                       0.22621  0.4756  
##                 Run:ConditionComputer                      0.02859  0.1691  
##                 Run:ConditionDisPeer                       0.01814  0.1347  
##                 Run:Valence_prevpositive                   0.04652  0.2157  
##                 ConditionComputer:Valence_prevpositive     0.14549  0.3814  
##                 ConditionDisPeer:Valence_prevpositive      0.15980  0.3998  
##                 Run:ConditionComputer:Valence_prevpositive 0.03282  0.1812  
##                 Run:ConditionDisPeer:Valence_prevpositive  0.02525  0.1589  
##  Residual                                                  0.90277  0.9501  
##  Corr                                                             
##                                                                   
##  -0.95                                                            
##  -0.63  0.48                                                      
##  -0.66  0.56  0.97                                                
##  -0.66  0.61  0.90  0.93                                          
##   0.62 -0.59 -0.87 -0.87 -0.98                                    
##   0.51 -0.50 -0.88 -0.93 -0.93  0.89                              
##   0.50 -0.60 -0.65 -0.76 -0.87  0.84  0.92                        
##   0.60 -0.55 -0.94 -0.93 -0.94  0.93  0.96  0.84                  
##   0.52 -0.45 -0.94 -0.91 -0.93  0.92  0.93  0.77  0.98            
##  -0.51  0.60  0.68  0.78  0.89 -0.86 -0.92 -1.00 -0.86 -0.79      
##  -0.51  0.55  0.76  0.73  0.83 -0.86 -0.87 -0.83 -0.92 -0.91  0.84
##                                                                   
## Number of obs: 5260, groups:  participant_id, 78
## 
## Fixed effects:
##                                              Estimate Std. Error         df
## (Intercept)                                  0.113206   0.123645  95.582037
## Run                                         -0.063708   0.045919 100.439180
## ConditionComputer                           -0.028497   0.140271 113.975953
## ConditionDisPeer                             0.006164   0.132556 118.469864
## Valence_prevpositive                         0.047790   0.133099 121.257650
## Run:ConditionComputer                        0.030654   0.052041 134.256731
## Run:ConditionDisPeer                        -0.002053   0.047481 175.655729
## Run:Valence_prevpositive                    -0.004017   0.051701  97.192526
## ConditionComputer:Valence_prevpositive       0.015662   0.168605 193.975149
## ConditionDisPeer:Valence_prevpositive        0.009846   0.176920 238.930211
## Run:ConditionComputer:Valence_prevpositive  -0.007496   0.064058 179.832106
## Run:ConditionDisPeer:Valence_prevpositive   -0.007085   0.065972 163.087713
##                                            t value Pr(>|t|)
## (Intercept)                                  0.916    0.362
## Run                                         -1.387    0.168
## ConditionComputer                           -0.203    0.839
## ConditionDisPeer                             0.047    0.963
## Valence_prevpositive                         0.359    0.720
## Run:ConditionComputer                        0.589    0.557
## Run:ConditionDisPeer                        -0.043    0.966
## Run:Valence_prevpositive                    -0.078    0.938
## ConditionComputer:Valence_prevpositive       0.093    0.926
## ConditionDisPeer:Valence_prevpositive        0.056    0.956
## Run:ConditionComputer:Valence_prevpositive  -0.117    0.907
## Run:ConditionDisPeer:Valence_prevpositive   -0.107    0.915
## 
## Correlation of Fixed Effects:
##             (Intr) Run    CndtnC CndtDP Vlnc_p Rn:CnC Rn:CDP Rn:Vl_ CnC:V_
## Run         -0.921                                                        
## CondtnCmptr -0.737  0.651                                                 
## ConditnDsPr -0.790  0.705  0.714                                          
## Vlnc_prvpst -0.790  0.723  0.703  0.752                                   
## Rn:CndtnCmp  0.680 -0.729 -0.902 -0.644 -0.664                            
## Rn:CndtnDsP  0.695 -0.752 -0.639 -0.907 -0.687  0.692                     
## Rn:Vlnc_prv  0.691 -0.777 -0.608 -0.665 -0.897  0.692  0.735              
## CndtnCmp:V_  0.589 -0.538 -0.803 -0.566 -0.754  0.737  0.522  0.674       
## CndtnDsP:V_  0.553 -0.499 -0.515 -0.720 -0.719  0.474  0.666  0.635  0.555
## Rn:CndtC:V_ -0.540  0.604  0.715  0.518  0.700 -0.801 -0.572 -0.772 -0.901
## Rn:CndDP:V_ -0.511  0.562  0.461  0.646  0.656 -0.510 -0.722 -0.703 -0.508
##             CDP:V_ R:CC:V
## Run                      
## CondtnCmptr              
## ConditnDsPr              
## Vlnc_prvpst              
## Rn:CndtnCmp              
## Rn:CndtnDsP              
## Rn:Vlnc_prv              
## CndtnCmp:V_              
## CndtnDsP:V_              
## Rn:CndtC:V_ -0.500       
## Rn:CndDP:V_ -0.908  0.551
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
ggplot(data = subset(rt_data_mod, !is.na(Valence_prev)), aes(x=factor(Run), y=Correct_RT_logz, fill=Condition, alpha=Valence_prev)) + 
  geom_boxplot(outlier.shape = NA) + 
  theme_classic()
## Warning: Using alpha for a discrete variable is not advised.
## Warning: Removed 81 rows containing non-finite values (`stat_boxplot()`).

Makes no difference.

4.5 Are participants learning?

4.5.1 Reaction time difference between similar and dissimilar peers

In the later runs, is there a difference in reaction time between the similar and dissimilar peer conditions? How many participants show this learning effect?

rt_means_subj_cond_run <- ddply(rt_data_mod,c('participant_id','Condition','Run'), 
                                summarise, 
                                mean=mean(Correct_RT, na.rm=TRUE))

Calculate the difference in RT for similar and dissimilar peer conditions at run 4

r4_peer_diff <- data.frame(matrix(ncol = 2, nrow = 0))

# Name columns for the empty dataframe  
colnames(r4_peer_diff) <- c('ParticipantID', 'sim_dis_RT')

for (subj in unique(rt_means_subj_cond_run$participant_id)) {
  temp_subj_data <- rt_means_subj_cond_run[rt_means_subj_cond_run$participant_id == subj, ]
  
  temp_last_run <- temp_subj_data$Run[length(unique(temp_subj_data$Run))]
  
  temp_run_data <- temp_subj_data[temp_subj_data$Run == temp_last_run, ]
  temp_diff <- temp_run_data[temp_run_data$Condition == 'SimPeer', 'mean'] - temp_run_data[temp_run_data$Condition == 'DisPeer', 'mean']
  
  r4_peer_diff[nrow(r4_peer_diff) + 1,] = c(subj,temp_diff)
}

r4_peer_diff$sim_dis_RT <- as.numeric(r4_peer_diff$sim_dis_RT) 

ggplot(r4_peer_diff, aes(x=sim_dis_RT)) + geom_histogram() + theme_classic()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

prop_learn <- nrow(r4_peer_diff[r4_peer_diff$sim_dis_RT < 0, ]) / nrow(r4_peer_diff)

print(paste(round(prop_learn, 4)*100, '% of participants had faster RTs for similar peers than dissimilar peers for their last run.'))
## [1] "48.72 % of participants had faster RTs for similar peers than dissimilar peers for their last run."
t.test(r4_peer_diff$sim_dis_RT, alternative = "two.sided", var.equal = FALSE)
## 
##  One Sample t-test
## 
## data:  r4_peer_diff$sim_dis_RT
## t = -0.45751, df = 77, p-value = 0.6486
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.02934015  0.01837677
## sample estimates:
##    mean of x 
## -0.005481687

4.5.2 Do participants show a decrease in RT after receiving positive feedback compared to negative feedback?

Note that previous valence here is the previous valence of the trial within the same condition.

rt_means_subj_pval_run <- ddply(rt_data_mod,c('participant_id','Valence_prev','Run'), 
                                summarise, 
                                mean=mean(Correct_RT, na.rm=TRUE))

# Remove rows with NA
rt_means_subj_pval_run <- rt_means_subj_pval_run[complete.cases(rt_means_subj_pval_run), ]

Calculate the difference in RT for similar and dissimilar peer conditions at run 4

# Create a new column for for previous valence
r4_peer_diff$pos_neg_RT <- NA

for (subj in unique(rt_means_subj_pval_run$participant_id)) {
  temp_subj_data <- rt_means_subj_pval_run[rt_means_subj_pval_run$participant_id == subj, ]
  
  temp_last_run <- temp_subj_data$Run[length(unique(temp_subj_data$Run))]
  
  temp_run_data <- temp_subj_data[temp_subj_data$Run == temp_last_run, ]
  temp_diff <- temp_run_data[temp_run_data$Valence_prev == 'positive', 'mean'] - temp_run_data[temp_run_data$Valence_prev == 'negative', 'mean']
  
  r4_peer_diff[r4_peer_diff$ParticipantID == subj, 'pos_neg_RT'] = temp_diff
}

r4_peer_diff$pos_neg_RT <- as.numeric(r4_peer_diff$pos_neg_RT) 

ggplot(r4_peer_diff, aes(x=pos_neg_RT)) + geom_histogram() + theme_classic()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

prop_learn <- nrow(r4_peer_diff[r4_peer_diff$pos_neg_RT < 0, ]) / nrow(r4_peer_diff)

print(paste(round(prop_learn, 4)*100, '% of participants had faster RTs for trials that were precided by a positive outcome than negative outcomes, for their last run.'))
## [1] "41.03 % of participants had faster RTs for trials that were precided by a positive outcome than negative outcomes, for their last run."
t.test(r4_peer_diff$sim_dis_RT, alternative = "two.sided", var.equal = FALSE)
## 
##  One Sample t-test
## 
## data:  r4_peer_diff$sim_dis_RT
## t = -0.45751, df = 77, p-value = 0.6486
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.02934015  0.01837677
## sample estimates:
##    mean of x 
## -0.005481687

5 Group Analyses

Next, we will analyze run by condition interactions for non-autistic adolescents and autistic adolescents, individually.


5.1 Autistic

rt_data_mod_asd <- filter(rt_data_mod, group == 'autistic')
print(paste("There are ",length(unique(rt_data_mod_asd$participant_id)), 
            " autistic participants"))
## [1] "There are  24  autistic participants"
model_run_peer_asd <- lmer(Correct_RT_logz ~ Run*Condition + (1 + Run | participant_id), data = rt_data_mod_asd)
## boundary (singular) fit: see help('isSingular')
summary(model_run_peer_asd)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: Correct_RT_logz ~ Run * Condition + (1 + Run | participant_id)
##    Data: rt_data_mod_asd
## 
## REML criterion at convergence: 5673.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6173 -0.7303 -0.1506  0.5802  4.1777 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev. Corr 
##  participant_id (Intercept) 0.14443  0.3800        
##                 Run         0.02408  0.1552   -1.00
##  Residual                   0.95636  0.9779        
## Number of obs: 2012, groups:  participant_id, 24
## 
## Fixed effects:
##                         Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)              0.16544    0.11790   61.02160   1.403    0.166
## Run                     -0.07150    0.04563   53.99659  -1.567    0.123
## ConditionComputer       -0.05003    0.12569 1983.99969  -0.398    0.691
## ConditionDisPeer        -0.11646    0.12592 1984.07362  -0.925    0.355
## Run:ConditionComputer    0.02482    0.04645 1984.03551   0.534    0.593
## Run:ConditionDisPeer     0.05206    0.04647 1984.20435   1.120    0.263
## 
## Correlation of Fixed Effects:
##             (Intr) Run    CndtnC CndtDP Rn:CnC
## Run         -0.947                            
## CondtnCmptr -0.529  0.456                     
## ConditnDsPr -0.528  0.456  0.495              
## Rn:CndtnCmp  0.478 -0.504 -0.906 -0.448       
## Rn:CndtnDsP  0.478 -0.504 -0.448 -0.906  0.495
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')

In autistic adolescents, there are no significant main effects or interactions.

m.lst <- emtrends(model_run_peer_asd, "Condition", var="Run")
pairs(m.lst)
##  contrast           estimate     SE   df t.ratio p.value
##  SimPeer - Computer  -0.0248 0.0465 1963  -0.534  0.8544
##  SimPeer - DisPeer   -0.0521 0.0465 1964  -1.120  0.5016
##  Computer - DisPeer  -0.0272 0.0467 1963  -0.583  0.8290
## 
## Degrees-of-freedom method: kenward-roger 
## P value adjustment: tukey method for comparing a family of 3 estimates
ggplot(data = rt_data_mod_asd, aes(x=factor(Run), y=Correct_RT_logz, 
                                   fill=Condition)) + 
  geom_boxplot(outlier.shape = NA) + 
  geom_point(alpha=0.05, aes(fill=Condition),
             position = position_jitterdodge(dodge.width = 0.8)) +
  theme_classic()
## Warning: Removed 27 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 27 rows containing missing values (`geom_point()`).

5.2 Autistic vs Non-Autistic

In this analysis, we will examine specific contrasts between autistic and non-autistic adolescents. For example, we will test whether there are any group differences in reaction times for similar peers and the computer condition, throughout the task.